import numpy as np
import pandas as pd
import os

# 设置NumPy打印选项
np.set_printoptions(threshold=np.inf)

# 文件名列表
filenames = ["metrics.npy", "pred.npy", "true.npy"]
# 文件夹路径
file_path = './TimesNet'
# 创建一个空的DataFrame
df = pd.DataFrame()

# 读取每个文件并将其添加到DataFrame中
for filename in filenames:
    file_full_path = os.path.join(file_path, filename)
    loaded_array = np.load(file_full_path)
    if filename == "pred.npy":
        # 如果是 "pred.npy"，为列添加自定义标题
        col_titles = [f"pred{i}" for i in range(loaded_array.shape[1])] if len(loaded_array.shape) > 1 else ["pred"]
    elif filename == "true.npy":
        # 如果是 "true.npy"，为列添加自定义标题
        col_titles = [f"true{i}" for i in range(loaded_array.shape[1])] if len(loaded_array.shape) > 1 else ["true"]
    else:
        # 对于其他文件，使用默认标题
        col_titles = [f"col{i}" for i in range(loaded_array.shape[1])] if len(loaded_array.shape) > 1 else ["col"]

    # 将NumPy数组转换为DataFrame
    df_temp = pd.DataFrame(loaded_array.reshape(loaded_array.shape[0], -1), columns=col_titles)

    # 添加到总的DataFrame中
    df = pd.concat([df, df_temp], axis=1)

# 保存DataFrame到Excel文件
excel_file_path = './output.xlsx'
df.to_excel(excel_file_path, index=False)

print(f"Data saved to Excel file: {excel_file_path}")
